package com.example.demo.service;

import com.example.demo.entity.GenealogyPerson;
import com.example.demo.mapper.GenealogyPersonMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GenealogyPersonService {

    @Resource
    private GenealogyPersonMapper genealogyPersonMapper;

    public void add(GenealogyPerson person) {
        genealogyPersonMapper.insert(person);
    }

    public void update(GenealogyPerson person) {
        genealogyPersonMapper.updateById(person);
    }

    public void deleteById(Long personId) {
        genealogyPersonMapper.deleteById(personId);
    }

    public GenealogyPerson selectById(Long personId) {
        return genealogyPersonMapper.selectById(personId);
    }

    public List<GenealogyPerson> selectAll() {
        return genealogyPersonMapper.selectAll();
    }

    public List<GenealogyPerson> selectByGenealogyId(Long genealogyId) {
        return genealogyPersonMapper.selectByGenealogyId(genealogyId);
    }

    public PageInfo<GenealogyPerson> selectPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<GenealogyPerson> list = genealogyPersonMapper.selectAll();
        return PageInfo.of(list);
    }
}